//package com.example.gcode;
//
//import android.content.Context;
//import android.content.Intent;
//import android.content.SharedPreferences;
//import android.content.SharedPreferences.Editor;
//import android.content.pm.PackageManager;
//import android.net.Uri;
//import android.util.Log;
//import android.widget.Toast;
//
//import com.dropbox.client2.android.AndroidAuthSession;
//import com.dropbox.client2.android.AuthActivity;
//import com.dropbox.client2.session.AccessTokenPair;
//import com.dropbox.client2.session.AppKeyPair;
//import com.dropbox.client2.session.Session.AccessType;
//
//public class DropBoxAuthentication {
//
//	/* DROP BOX THINGS */
//	final static private String APP_KEY = "bx9eufdsdzpbxs5";
//	final static private String APP_SECRET = "tz6vorkhj2xvfv1";
//	private boolean mLoggedIn;
//	final static private String ACCOUNT_PREFS_NAME = "prefs";
//	final static private String ACCESS_KEY_NAME = "ACCESS_KEY";
//	final static private String ACCESS_SECRET_NAME = "ACCESS_SECRET";
//    Context context;
//
//	public DropBoxAuthentication(Context context) {
//		this.context = context;
//	}
//
//	public void checkAppKeySetup() {
//		// Check to make sure that we have a valid app key
//		if (APP_KEY.startsWith("CHANGE") || APP_SECRET.startsWith("CHANGE")) {
//			showToast("You must apply for an app key and secret from developers.dropbox.com, and add them to the GCloud ap before trying it.");			
//			return;
//		}
//
//		// Check if the app has set up its manifest properly.
//		Intent testIntent = new Intent(Intent.ACTION_VIEW);
//		String scheme = "db-" + APP_KEY;
//		String uri = scheme + "://" + AuthActivity.AUTH_VERSION + "/test";
//		testIntent.setData(Uri.parse(uri));
//		PackageManager pm = context.getPackageManager();
//		if (0 == pm.queryIntentActivities(testIntent, 0).size()) {
//			showToast("URL scheme in your app's "
//					+ "manifest is not set up correctly. You should have a "
//					+ "com.dropbox.client2.android.AuthActivity with the "
//					+ "scheme: " + scheme);			
//		}
//	}
//
//	public  AndroidAuthSession buildSession() {
//		AppKeyPair appKeyPair = new AppKeyPair(APP_KEY, APP_SECRET);
//		AndroidAuthSession session;
//
//		String[] stored = getKeys();
//		if (stored != null) {
//			Log.i("buildSession", " getting key stored:");
//			AccessTokenPair accessToken = new AccessTokenPair(stored[0],
//					stored[1]);
//			session = new AndroidAuthSession(appKeyPair, AccessType.DROPBOX,
//					accessToken);
//		} else {
//			Log.i("buildSession",
//					"getting key not stored, going to build a new one");
//			session = new AndroidAuthSession(appKeyPair, AccessType.DROPBOX);
//		}
//		if (session != null) {
//			Log.i("buildSession", " session is not null");
//		}
//		return session;
//	}
//
//	public  String[] getKeys() {
//		SharedPreferences prefs = context.getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
//		String key = prefs.getString(ACCESS_KEY_NAME, null);
//		String secret = prefs.getString(ACCESS_SECRET_NAME, null);
//		if (key != null && secret != null) {
//			String[] ret = new String[2];
//			ret[0] = key;
//			ret[1] = secret;
//			return ret;
//		} else {
//			return null;
//		}
//	}
//	
//	public void setLoggedIn(boolean loggedIn) {
//		mLoggedIn = loggedIn;
//		Log.i("setLoggedIn() ", String.valueOf(mLoggedIn));
//	}
//
//	public void storeKeys(String key, String secret) {
//		// Save the access key for later
//		SharedPreferences prefs = context.getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
//		Editor edit = prefs.edit();
//		edit.putString(ACCESS_KEY_NAME, key);
//		edit.putString(ACCESS_SECRET_NAME, secret);
//		edit.commit();
//	}
//
//	
//	public void showToast(final String toast) {
//		runOnUiThread(new Runnable() {
//			@Override
//			public void run() {
//				Toast.makeText(context, toast,
//						Toast.LENGTH_SHORT).show();
//			}
//		});
//	}
//}
